<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="人数限制"
      :visible="open"
      width="500px"
      append-to-body
      @close="cancel()"
    >
      <el-form @submit.native.prevent ref="form" :model="form" :rules="rules" label-width="160px">
        <el-form-item :label="`${$courseName?$courseName:'课程'}名称`" prop="chapterName">
          {{ form.chapterName }}
        </el-form-item>

        <el-form-item :label="`${$workstationName?$workstationName:'工作站'}名称`" prop="chapterName">
          {{ form.chapterName }}
        </el-form-item>
        <el-form-item :label="`${$workstationName?$workstationName:'工作站'}可容纳学生人数`" prop="chapterName">
          {{ form.chapterName }}
        </el-form-item>
        <el-form-item :label="`${$courseName?$courseName:'课程'}可选人数上限`" prop="num">
          <el-input-number
            :min='0'
            placeholder="请输入"
            v-model="form.num"
            controls-position="right"
          ></el-input-number>
          人
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick @click="cancel">取 消</el-button>
        <el-button v-preventReClick type="primary" @click="submitForm">确 定</el-button>

      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    open: Boolean,
    type: Number,
    id: Number,
  },
  data() {
    return {
      // 表单参数
      form: {
        num: undefined,
      },
      // 表单校验
      rules: {
        num: [{ required: true, message: "请选择人数", trigger: "blur" }],
      },
    };
  },
  watch: {
    open(e) {
      if (e) {
        console.log("查询课程信息");
        //TODO 查询课程信息详情
        //   getPost_workstation(this.id).then((res) => {
        //     this.form = res.data;
        //   });
      }
    },
  },
  mounted() {},
  methods: {
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          //TODO 调用限制人数接口
          this.$modal.msgSuccess("限制人数成功");
          this.$emit("refresh", true);
          this.$emit("update:open", false);
        }
      });
    },
    // 表单重置
    reset() {
      this.form = {
        num: undefined,
      };
      this.resetForm("form");
    },
    cancel() {
      this.$emit("update:open", false);
      this.reset();
    },
  },
};
</script>
<style scoped lang="scss"></style>
